package com.earthea.common.util;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

/**
 * 随机数
 */
public class RandomUtils {
    private static final SecureRandom RANDOM;

    static {
        try {
            RANDOM = SecureRandom.getInstanceStrong();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("fail init secure random", e);
        }
    }

    public static int nextInt(int bound) {
        return RANDOM.nextInt(bound);
    }

    public static int nextInt(int start, int end) {
        return RANDOM.nextInt(Math.abs(end - start)) + Math.min(start, end);
    }

}
